<script setup>
import { ref } from 'vue';

// 定义消息列表数据
const messages = ref([
  {
    id: 1,
    type: 'official',
    title: '热门活动：周末狂欢剧本杀',
    content: '周末来店体验热门剧本，享受八折优惠，还有精美礼品相送！',
    time: '2025-06-02 10:00',
    isTop: true
  },
  {
    id: 2,
    type: 'reservation',
    title: '预约成功通知',
    content: '您已成功预约周六下午 3 点的《神秘庄园》剧本杀场次，请按时到场。',
    time: '2025-06-02 14:30',
    isTop: false
  }
]);

// 处理消息列表，置顶官方消息
const sortedMessages = messages.value.sort((a, b) => {
  return b.isTop - a.isTop;
});
</script>

<template>

  <div class="message-container">
    <h2>剧本杀消息列表</h2>
    <div class="message-list">
      <div 
        v-for="message in sortedMessages" 
        :key="message.id" 
        class="message-item"
        :class="{ 'official-message': message.type === 'official' }"
      >
        <div class="message-header">
          <span class="message-title">{{ message.title }}</span>
          <span v-if="message.isTop" class="top-tag">置顶</span>
          <span class="message-time">{{ message.time }}</span>
        </div>
        <div class="message-content">{{ message.content }}</div>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.message-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px;
  font-family: 'Arial', sans-serif;

  h2 {
    text-align: center;
    color: #333;
    margin-bottom: 20px;
  }

  .message-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
  }

  .message-item {
    background-color: #fff;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease;

    &:hover {
      transform: translateY(-3px);
    }

    .message-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 10px;

      .message-title {
        font-weight: bold;
        font-size: 18px;
        color: #333;
      }

      .top-tag {
        background-color: #ff9800;
        color: white;
        padding: 2px 8px;
        border-radius: 4px;
        font-size: 12px;
        margin-left: 10px;
      }

      .message-time {
        font-size: 14px;
        color: #999;
      }
    }

    .message-content {
      font-size: 16px;
      color: #666;
      line-height: 1.5;
    }
  }

  .official-message {
    border-left: 4px solid #ff9800;
  }
}
</style>